package com.atguigu.gmall.controller;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.list.Goods;
import com.atguigu.gmall.model.list.SearchParam;
import com.atguigu.gmall.model.list.SearchResponseVo;
import com.atguigu.gmall.service.SearchService;
import io.swagger.annotations.ApiOperation;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/list")
public class SearchController {

    @Autowired
    private ElasticsearchRestTemplate restTemplate;


    @Autowired
    private SearchService searchService;


    @GetMapping("inner/createIndex")
    public Result createIndex(){
        restTemplate.createIndex(Goods.class);
        restTemplate.putMapping(Goods.class);
        return Result.ok();
    }

    @GetMapping("/inner/upperGoods/{skuId}")
    public Result upperGoods(@PathVariable Long skuId){
        searchService.upperGoods(skuId);
        return Result.ok();
    }

    @GetMapping("inner/lowerGoods/{skuId}")
    public Result lowerGoods(@PathVariable Long skuId){
        searchService.lowerGoods(skuId);
        return Result.ok();
    }
    @ApiOperation("商品热度")
    @GetMapping("/inner/addHotScore/{skuId}")
    public void addHotScore(@PathVariable Long skuId){
        searchService.addHotScore(skuId);
    }


    @PostMapping("/inner/getSearchList")
    public SearchResponseVo getSearchList(@RequestBody SearchParam searchParam){
        SearchResponseVo searchResponseVo = searchService.getSearchList(searchParam);
        return searchResponseVo;
    }
}
